var webpack = require('webpack');
var path = require('path');
var autoprefixer = require('autoprefixer');

module.exports = {
	entry: './src/js/index.js',
	output: {
		path: path.resolve(__dirname, 'dist'),
		publicPath: '/dist/',
		filename: 'bundle.js'
	},
	module: {
		loaders: [{
			// 使用babel-loader加载jsx资源
			test: /\.jsx?$/,
			exclude: /node_modules/,
			loader: 'babel-loader',
			query: {
				presets: [
					'es2015',
					'react',
					'stage-0'
				],
			}
		}, {
			// 使用style-loader, css-loader, postcss-loader加载css资源
			test: /\.css$/,
			loaders: [
				'style-loader',
				'css-loader?modules',
				'postcss-loader'
			]
		}, {
			// 使用url-loader加载图片资源
			test: /\.(png|jpg)$/,
			loader: 'url-loader?limit=40000'
		}]
	},
	postcss: [
		// 自动为样式添加兼容性前缀
		autoprefixer()
	],
	plugins: [
		// 自动给打包后的文件加文件头
		new webpack.BannerPlugin('Copyright © 2016 Kid. All rights reserved.'),
		// 优先考虑使用最多的模块，并为它们分配最小的id
		new webpack.optimize.OccurenceOrderPlugin(),
		// 使用热更新模块
		new webpack.HotModuleReplacementPlugin()
	],
	devServer: {
		historyApiFallback: true,
		disableHostCheck: true,
		hot: true,
		inline: true,
		host: '0.0.0.0',
		port: 8003
	}
};
